package tool.workflow.fsSoft

import implicits.Implicits._
import play.api.i18n.Messages
import shared.Pojo.PcaSoftT
import shared.pojo.WorkflowMission.EachPcaData
import shared.tool.DefaultPickle
import tool.Pojo._
import tool._
import tool.plot._
import tool.softT._
import tool.workflow.fsSoft.AllFsSoft.FSSoftBT

import java.io.File

/**
 * Created by yz on 3/12/2020
 */
object Pca extends FSSoftBT with PcaSoftBT {

  def produceSubConfigFile(workspaceDir: File, data: EachPcaData) = {
    val subConfigFile = new File(workspaceDir, "calculate_config.json")
    DefaultPickle.write(data).toFile(subConfigFile)
  }

  override def produceInput(workspaceDir: File, resultDir: File, index: Int, parentNodeStr: String, id: String)(
    implicit dao: MyDao,messages: Messages): Unit = {
    val groupFile = new File(workspaceDir.getParentFile, "group.txt")
    val fsData = FeatureSelectionTool.getFsData(workspaceDir.getParentFile)
    groupFile.txtLines.lineSeqMap.filter { map =>
      fsData.pca(index).groups.contains(map("ClassNote"))
    }.csvLines.toTxtFile(new File(workspaceDir, "group.txt"))
    FeatureSelectionTool.produceSubInputFile(workspaceDir, parentNodeStr)
    val data = FeatureSelectionTool.getFsData(workspaceDir.getParentFile).pca(index)
    produceSubConfigFile(workspaceDir, data)
  }

}
